package com.net.example;
import java.net.InetAddress;  
import java.net.UnknownHostException;  
  
public class Domain2Ip {  
    public static void main(String[] args) {  
        InetAddress iAddress;  
        InetAddress iAddress2;  
        try {  
            // 获取本机的地址  
            iAddress = InetAddress.getLocalHost();  
            System.out.println("主机名：" + iAddress.getHostName());  
            System.out.println("字符串ip：" + iAddress.getHostAddress());  
  
            iAddress2 = InetAddress.getByName("www.baidu.com");  
            // 注意事项：有可能返回的主机ip有很多,只是显示了中的一个  
            System.out.println(iAddress2.getHostAddress());  
  
        } catch (UnknownHostException e) {  
            e.printStackTrace();  
        }  
  
    }  
}